/*
 * @Author: Arcanum
 * @Copyright: 2010 by Mastercoding.NET
 * @Date: 22. July 2010
 * @File: mclib.cpp
 */


void mcError(const char *str)
{
    sceGuFinish();
    sceGuSync(0,0);
    FPS();
    fbp0 = sceGuSwapBuffers();

    sceDisplayWaitVblankStart();
    pspDebugScreenSetXY(0, 0);
    pspDebugScreenPrintf(str);
    sceKernelDelayThread(4000000);
    sceKernelExitGame();
}

void WaitSplash()
{   
    if(waitsplash)
    {
        if(Data.SplashTime < 2)
            Data.SplashTime += dt;
        else {
            Data.SplashTime = 0;
            waitsplash = false;
            showbar = true;
            Monkey.LockMove = false;
            levelsplash = Monkey.Level;
        }
    } else if(waitgameover)
    {
        sceKernelDelayThread(2000000);
        waitgameover = false;
        step = 2;
        Monkey.Pos.x = Rmap.spawn_x;
        Monkey.Pos.y = Rmap.spawn_y;
        Monkey.State = MONKEY_NORM;
        Monkey.Lives = 2;
        Monkey.LockMove = false;
    }
}

void LoadTextures()
{
    char mmbgchar[21] = "src/misc/credits.tga";
    if(!credits_bg.LoadTGA(mmbgchar))
    {
        mcError("Error: Failed to load credits.tga");
    }
    credits_bg.Swizzle();
    
    
    
    char mmbgchar2[18] = "src/misc/menu.tga";
    if(!mm_bg.LoadTGA(mmbgchar2))
    {
        mcError("Error: Failed to load menu.tga");
    }
    char mmpt[23] = "src/spr/mm_pointer.tga";
    if(!mm_pointer.LoadTGA(mmpt))
    {
        mcError("Error: Failed to load mm_pointer.tga");
    }
    mm_pointer.Swizzle();
    mm_bg.Swizzle();
    
    char txl1[17] = "src/spr/misc.tga";
    char txl2[16] = "src/spr/npc.tga";
    char txl3[19] = "src/spr/monkey.tga";

    if(!spr_misc.LoadTGA(txl1))
        mcError("Error: Failed to load misc.tga");
    
    if(!spr_npc.LoadTGA(txl2))
        mcError("Error: Failed to load npc.tga");
    
    if(!spr_monkey.LoadTGA(txl3))
        mcError("Error: Failed to load monkey.tga");
}